package com.tanhua.api.mongo;

import com.tanhua.domain.mongo.Visitors;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@Service
public class MovementsApiImpl implements MovementsApi {
    @Autowired
    private MongoTemplate mongoTemplate;
    //登录查询上次时间点到现在的访客信息
    public List<Visitors> findvisitors(Long id, Long timeValue) {
        //条件
        Query query = new Query(Criteria.where("userId").is(id)
        .and("date").gt(timeValue));
        //排序
        query.with(new Sort(Sort.Direction.DESC,"date"));
        //查询5条
        query.limit(5);

        List<Visitors> visitorsList = mongoTemplate.find(query, Visitors.class);
        return visitorsList;
    }
}
